package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工分类管理
 */
@Api(tags = "员工分类管理")
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/admin/category")
@RestController
public class CategoryController {


    private final CategoryService categoryService;

    /**
     * 分类分页查询
     *
     * @param cpqDTO the cpq dto
     * @return the result
     */
    @ApiOperation("员工分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageList(CategoryPageQueryDTO cpqDTO) {
        PageResult pageResult = categoryService.pageList(cpqDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据类型查询分类
     *
     * @param type the type
     * @return the result
     */
    @ApiOperation("根据类型查询分类")
    @GetMapping("/list")
    public Result<List<Category>> list(@RequestParam(value = "type") Integer type) {
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }


    /**
     * 根据id删除分类
     *
     * @param id the id
     * @return the result
     */
    @ApiOperation("根据id删除分类")
    @DeleteMapping
    public Result<?> removeById(@RequestParam(value = "id") Long id) {
        categoryService.removeById(id);
        return Result.success();
    }


    /**
     * 添加分类
     *
     * @param categoryDTO the category dto
     * @return the result
     */
    @ApiOperation("添加分类")
    @PostMapping
    public Result<?> increase(@RequestBody CategoryDTO categoryDTO) {
        categoryService.increase(categoryDTO);
        return Result.success();
    }


    /**
     * 启用、禁用分类
     *
     * @param status the status
     * @param id     the id
     * @return the result
     */
    @ApiOperation("启用、禁用分类")
    @PostMapping("/status/{status}")
    public Result<?> status(@PathVariable Integer status,@RequestParam(value = "id")Long id){
        categoryService.status(id,status);
        return Result.success();
    }

    /**
     *  修改分类
     *
     * @param categoryDTO the category dto
     * @return the result
     */
    @ApiOperation("修改分类")
    @PutMapping
    public Result<?> update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

}
